//
//  HUserSet.m
//  HTanzhi
//
//  Created by 陈贵 on 15/11/10.
//  Copyright © 2015年 hzj. All rights reserved.
//

#import "HUserSet.h"
#import "HUserSetData.h"
#import "HScanView.h"
#import "HLocationView.h"

@interface HUserSet ()

@end

@implementation HUserSet

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UIView *fv = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1)];
    fv.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1];
    self.tableView.tableHeaderView = fv;
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.userData.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.userData[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"HUserSetCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    //取模型
    NSArray *arrModel = self.userData[indexPath.section];
    HUserSetData *model = arrModel[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    cell.imageView.image = [UIImage imageNamed:model.icon];
    cell.textLabel.text = model.name;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    NSLog(@"xing");
    UIViewController *v;
    if (indexPath.section == 0 && indexPath.row == 0) {
        v = [[HScanView alloc]init];
        v.view.backgroundColor = [UIColor brownColor];
    }else if (indexPath.section == 0 && indexPath.row == 1){
        v = [[HLocationView alloc]init];
    }else{
        v = [[UIViewController alloc]init];
        v.view.frame = CGRectMake(0, 0, 200, 200);
        v.view.backgroundColor = [UIColor greenColor];
    }
    [self.navigationController pushViewController:v animated:YES];
}

///懒加载数据
- (NSArray *)userData
{
    if (_userData == nil) {
        _userData = [[NSArray alloc]init];
    }
    return _userData;
}
@end
